////////////////////////////////////////////////////////////////////////////////
// Copyright 2005 CORE Solutions Limited
// All rights reserved.
// PROPRIETARY AND CONFIDENTIAL INFORMATION.
// Use is subject to license terms.
//
// FUNCTION ID      :   MENU_GROUP_LABEL
// AUTHOR           :   Victor Zheng 
// DATE CREATE      :   2005/12/21
// DESCRIPTION      :   a ACTION file for the function, MENU_GROUP_LABEL
//                  :   
//                  :   
//                  :   
//
// MODIFICATION HISTORY:
// DATE         AUTHOR          VERSION NO.         COMMENT
// -----------  --------------  ------------------  -------------------
// 2005/12/21   Victor Zheng    1.0                 source is generated.
//
//
//
////////////////////////////////////////////////////////////////////////////////

package com.erp.app.admin.menuGroupLabel.web;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.erp.app.admin.menuGroupLabel.criteria.MenuGroupLabelSrchCriteria;
import com.erp.app.admin.menuGroupLabel.vo.MenuGroupLabelVo;
import com.erp.app.common.ProjectConstants;
import com.erp.app.util.web.WebUtil;
import com.erp.framework.controller.action.SimplePageEditStyleAction;
import com.erp.framework.util.CommonUtil;
import com.erp.framework.util.logger.Logger;
import com.erp.framework.util.user.User;

/**
* A <strong>Page Edit Action</strong> is an adapter between the contents of an incoming
* HTTP request and the corresponding business logic that should be executed to
* process this request.  The controller (ActionServlet) will select an
* appropriate Action for each request.
* The main purpose for this action class is to handle the one-page document events
* from the web browsers.
*
* @author          Victor Zheng 
* @version 1.0     2005/12/21
* @since           FrameWork 1.0
*
*/
public class MenuGroupLabelAction extends SimplePageEditStyleAction {

    ////////////////////////////////////////////////////////////////////////////////
    // CONSTANTS DEFINITION
    ////////////////////////////////////////////////////////////////////////////////

    //public static final String ACTION_DO_SOMETHING = "actionDoSomething";
    //public static final String STATUS_DO_SOMETHING = "statusDoSomething";


    ////////////////////////////////////////////////////////////////////////////////
    // GLOBAL VARIABLES DEFINITION
    ////////////////////////////////////////////////////////////////////////////////



    ////////////////////////////////////////////////////////////////////////////////
    // LOGICAL AND BUSINESS METHODS
    ////////////////////////////////////////////////////////////////////////////////

    public ActionForward handlePageEvent(ActionMapping mapping, ActionForm formIn,
        HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

        HttpSession session = request.getSession(false);
        MenuGroupLabelForm form = (MenuGroupLabelForm) formIn;
        String action = form.getPageEvent();
        ActionForward actionForward = new ActionForward(mapping.getInput());
        User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

        try {
//          if (!isHandled(request) && action.equalsIgnoreCase(ACTION_DO_SOMETHING)) {
//              actionForward = processActionDoSomething(mapping, formIn, request, response, errors);
//              setHandled(request);
//              saveToken(request);
//          }

        } catch (Exception e) {
            Logger.logExceptions(this, e);
        }

        return actionForward;
    }

    protected ActionForward processOtherStatus(ActionMapping mapping, ActionForm formIn,
        HttpServletRequest request, HttpServletResponse response,
        ActionErrors errors, String rb_status) {

        HttpSession session = request.getSession(false);
        MenuGroupLabelForm form = (MenuGroupLabelForm) formIn;
        String action = form.getPageEvent();
        ActionForward actionForward = new ActionForward(mapping.getInput());
        User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

        try {
//          if (rb_status.equalsIgnoreCase(STATUS_DO_SOMETHING)) {
//              return processStatusDoSomething(mapping,  formIn,  request, response,  errors,  rb_status);
//          }
        } catch (Exception e) {
            Logger.log(this, e);
        }

        return actionForward;
    }

    //uncomment the following code and implement the method if necessary
    /*
    protected ActionForward processActionDoSomething(ActionMapping mapping, ActionForm formIn,
        HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

        HttpSession session = request.getSession(false);
        MenuGroupLabelForm form = (MenuGroupLabelForm) formIn;
        String action = form.getPageEvent();
        ActionForward actionForward = new ActionForward(mapping.getInput());
        User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

        try{
            System.out.println("You are in processActionDoSomething().");
        } catch (Exception e) {
            Logger.logExceptions(this, e);
        }

        return actionForward;
    }
    */

    //uncomment the following code and implement the method if necessary
    /*
    protected ActionForward processStatusDoSomething(ActionMapping mapping, ActionForm formIn,
        HttpServletRequest request, HttpServletResponse response,
        ActionErrors errors, String rb_status) {

        HttpSession session = request.getSession(false);
        MenuGroupLabelForm form = (MenuGroupLabelForm) formIn;
        String action = form.getPageEvent();
        ActionForward actionForward = new ActionForward(mapping.getInput());
        User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

        try{
            System.out.println("You are in processStatusDoSomething().");
        } catch (Exception e) {
            Logger.logExceptions(this, e);
        }

        return actionForward;
    }
    */

    //----------------------------------------------------------------------------//
    //add your new business/logical methods/functions HERE
    //----------------------------------------------------------------------------//


    ////////////////////////////////////////////////////////////////////////////////
    // END OF LOGICAL AND BUSINESS METHODS
    ////////////////////////////////////////////////////////////////////////////////


    ////////////////////////////////////////////////////////////////////////////////
    // OVERRIDES PARENT'S OPTIONAL METHODS
    ////////////////////////////////////////////////////////////////////////////////

    //the following method is only to be overwritten by sub-class if intended
    //to set the aut-search on-load to on/off
    protected boolean getLoadOnEnter() {

        //auto-search when load
        return true;
    }

    //the following method is only to be overwritten by sub-class if intended
    //to set the clearing search result sets on-load to on/off
    protected boolean getResetOnEnter() {

        //reset last searched results when load 
        return false;
    }

    protected void initAction(ActionMapping mapping, ActionForm formIn,
        HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

        super.initAction(mapping, formIn, request, response, errors);

        HttpSession session = request.getSession(false);
        MenuGroupLabelForm form = (MenuGroupLabelForm) formIn;
        String action = form.getPageEvent();
        ActionForward actionForward = new ActionForward(mapping.getInput());
        User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

        try {

        } catch (Exception e) {
            Logger.logExceptions(this, e);
        }
    }

    protected void initForm(ActionMapping mapping, ActionForm formIn,
        HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

        super.initForm(mapping, formIn, request, response, errors);

        HttpSession session = request.getSession(false);
        MenuGroupLabelForm form = (MenuGroupLabelForm) formIn;
        String action = form.getPageEvent();
        ActionForward actionForward = new ActionForward(mapping.getInput());
        User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

        try {

        } catch (Exception e) {
            Logger.logExceptions(this, e);
        }
    }

    protected void initPage(ActionMapping mapping, ActionForm formIn,
        HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

        super.initPage(mapping, formIn, request, response, errors);

        HttpSession session = request.getSession(false);
        MenuGroupLabelForm form = (MenuGroupLabelForm) formIn;
        String action = form.getPageEvent();
        ActionForward actionForward = new ActionForward(mapping.getInput());
        User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

        try {

        } catch (Exception e) {
            Logger.logExceptions(this, e);
        }
    }

    protected void beforeSearch(ActionMapping mapping, ActionForm formIn,
        HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

        HttpSession session = request.getSession(false);
        MenuGroupLabelForm form = (MenuGroupLabelForm) formIn;
        String action = form.getPageEvent();
        ActionForward actionForward = new ActionForward(mapping.getInput());
        User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

        try {

        } catch (Exception e) {
            Logger.logExceptions(this, e);
        }
    }

    protected void afterSearch(ActionMapping mapping, ActionForm formIn,
        HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

        HttpSession session = request.getSession(false);
        MenuGroupLabelForm form = (MenuGroupLabelForm) formIn;
        String action = form.getPageEvent();
        ActionForward actionForward = new ActionForward(mapping.getInput());
        User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

        try {

        } catch (Exception e) {
            Logger.logExceptions(this, e);
        }
    }

    protected void beforeSave(ActionMapping mapping, ActionForm formIn,
        HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

        HttpSession session = request.getSession(false);
        MenuGroupLabelForm form = (MenuGroupLabelForm) formIn;
        String action = form.getPageEvent();
        ActionForward actionForward = new ActionForward(mapping.getInput());
        User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

        try {

        } catch (Exception e) {
            Logger.logExceptions(this, e);
        }
    }

    protected void afterSave(ActionMapping mapping, ActionForm formIn,
        HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

        HttpSession session = request.getSession(false);
        MenuGroupLabelForm form = (MenuGroupLabelForm) formIn;
        String action = form.getPageEvent();
        ActionForward actionForward = new ActionForward(mapping.getInput());
        User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

        try {

        } catch (Exception e) {
            Logger.logExceptions(this, e);
        }
    }

    protected void beforeRefresh(ActionMapping mapping, ActionForm formIn,
        HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

        HttpSession session = request.getSession(false);
        MenuGroupLabelForm form = (MenuGroupLabelForm) formIn;
        String action = form.getPageEvent();
        ActionForward actionForward = new ActionForward(mapping.getInput());
        User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

        try {

        } catch (Exception e) {
            Logger.logExceptions(this, e);
        }
    }

    protected void afterRefresh(ActionMapping mapping, ActionForm formIn,
        HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

        HttpSession session = request.getSession(false);
        MenuGroupLabelForm form = (MenuGroupLabelForm) formIn;
        String action = form.getPageEvent();
        ActionForward actionForward = new ActionForward(mapping.getInput());
        User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

        try {

        } catch (Exception e) {
            Logger.logExceptions(this, e);
        }
    }

    protected void beforeAddRow(ActionMapping mapping, ActionForm formIn,
        HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

        HttpSession session = request.getSession(false);
        MenuGroupLabelForm form = (MenuGroupLabelForm) formIn;
        String action = form.getPageEvent();
        ActionForward actionForward = new ActionForward(mapping.getInput());
        User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

        try {

        } catch (Exception e) {
            Logger.logExceptions(this, e);
        }
    }


        //TODO: Add the following line to ProjectSecurityConstants.java
        //public static final String SP_SHARE_MENU_GROUP_LABEL = "SP_SHARE_MENU_GROUP_LABEL";
    protected void afterAddRow(ActionMapping mapping, ActionForm formIn,
        HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

        HttpSession session = request.getSession(false);
        MenuGroupLabelForm form = (MenuGroupLabelForm) formIn;
        String action = form.getPageEvent();
        ActionForward actionForward = new ActionForward(mapping.getInput());
        User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

        try {
            ArrayList rows = form.getMultiRows();
            if (rows != null && rows.size() > 0) {
                MenuGroupLabelRow row = (MenuGroupLabelRow) rows.get(rows.size() - 1);
                row.setCompanyCode(WebUtil.getAppropriateCompanyCode(session, ProjectConstants.SP_SHARE_MENU_GROUP_LABEL));
            }
        } catch (Exception e) {
            Logger.logExceptions(this, e);
        }
    }

    protected void beforeDeleteRow(ActionMapping mapping, ActionForm formIn,
        HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

        HttpSession session = request.getSession(false);
        MenuGroupLabelForm form = (MenuGroupLabelForm) formIn;
        String action = form.getPageEvent();
        ActionForward actionForward = new ActionForward(mapping.getInput());
        User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

        try {

        } catch (Exception e) {
            Logger.logExceptions(this, e);
        }
    }

    protected void afterDeleteRow(ActionMapping mapping, ActionForm formIn,
        HttpServletRequest request, HttpServletResponse response, ActionErrors errors) {

        HttpSession session = request.getSession(false);
        MenuGroupLabelForm form = (MenuGroupLabelForm) formIn;
        String action = form.getPageEvent();
        ActionForward actionForward = new ActionForward(mapping.getInput());
        User editingUser = (User) session.getAttribute(ProjectConstants.SESSION_USER);

        try {

        } catch (Exception e) {
            Logger.logExceptions(this, e);
        }
    }

    protected String getSimpleSrchMenuId() {

        //TODO: Add the following line to ProjectMenuConstants.java
        //public static final String MOD_MENU_GROUP_LABEL = "MOD_MENU_GROUP_LABEL";
        return ProjectConstants.MOD_MENU_GROUP_LABEL;
    }

    ////////////////////////////////////////////////////////////////////////////////
    // END OF OPTIONAL METHODS
    ////////////////////////////////////////////////////////////////////////////////


    ////////////////////////////////////////////////////////////////////////////////
    // IMPLEMENTS PARENT'S ABSTRACT METHODS
    ////////////////////////////////////////////////////////////////////////////////

    protected String getModuleName(ActionMapping mapping, ActionForm formIn,
        HttpServletRequest request,HttpServletResponse response) {

        //TODO: Add the following line to ProjectMenuConstants.java
        //public static final String MOD_MENU_GROUP_LABEL = "MOD_MENU_GROUP_LABEL";
        return ProjectConstants.MOD_MENU_GROUP_LABEL;
    }

    protected String getFunctionId() {

        //struts-config xxxxx.do
        return "menuGroupLabel.do";
    }

    protected void setFormType(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
         HttpServletResponse response, ActionErrors errors) {

        MenuGroupLabelForm form = (MenuGroupLabelForm) formIn;
        form.setFormType(ProjectConstants.FORM_TYPE_PAGE_EDIT);
    }

    protected String getMasterDelegateName() {

        //the corresponding delegate session name
        return "menuGroupLabelDelegate";
    }

    protected Class getMasterFormClass() {

        //the corresponding form class
        return MenuGroupLabelForm.class;
    }

    protected Class getMasterVOClass() {

        //corresponding master vo class
        return MenuGroupLabelVo.class;
    }

    protected Class getDetailVOClass() {

        //corresponding detail vo class
        return MenuGroupLabelVo.class;
    }

    protected Class getDetailFormClass() {
        //corresponding detail row class
        return MenuGroupLabelRow.class;
    }

    protected String getDetailFormSessionName() {

        //corresponding detail form session name
        return "menuGroupLabelForm";
    }

    protected Class getSearchCriteriaClass() {

        //corresponding searching criteria class
        return MenuGroupLabelSrchCriteria.class;
    }

    protected void setOtherCriteria(ActionMapping mapping, ActionForm formIn,
            HttpServletRequest request, HttpServletResponse response,
            ActionErrors errors, Object criteria) {

            HttpSession session = request.getSession(false);
            User user = (User) session.getAttribute(ProjectConstants.SESSION_USER);
            MenuGroupLabelSrchCriteria crit = (MenuGroupLabelSrchCriteria) criteria;

            //TODO: Add the following line to ProjectSecurityConstants.java
            //public static final String SP_SHARE_MENU_GROUP_LABEL = "SP_SHARE_MENU_GROUP_LABEL";
            String companyCode = WebUtil.getAppropriateCompanyCode(session, ProjectConstants.SP_SHARE_MENU_GROUP_LABEL);
            String sysLang = (String)session.getAttribute(ProjectConstants.SESSION_SYSTEM_LANG);
            if(CommonUtil.isEmpty(sysLang)){
                sysLang = LANG_DEFAULT;
            }

            crit.setSrchCompanyCode(companyCode);
            crit.setSrchLangCodeFr(sysLang);
            crit.setSrchLangCodeTo(sysLang);
        }

    ////////////////////////////////////////////////////////////////////////////////
    // END OF ABSTRACT METHODS
    ////////////////////////////////////////////////////////////////////////////////
}
